<template>
  <div ref="content" >
    <!-- 面包屑 -->
    <div class="bread">
      <div class="l">
        首页>
        <span class="txt">双循环</span>
        <div class="normal">
          <div class="i">>></div>正常
        </div>
      </div>
      <div class="r">
        <img src="../../assets/imags/city.png" alt />
        <div class="qian">牵头单位:</div>
        <div class="tai">玉环市商务局</div>
      </div>
    </div>
    <div class="container">
      <div class="title">
        <div @click="handleTab" :class="[showTab?tab1:tab2]" class="hexin">核心指标</div>
        <div @click="handleTab2" :class="[showTab?tab2:tab1]" class="neiwai">内外贸一体化</div>
      </div>
      <div class="core" v-show="showTab">
        <div class="button">
          <el-button @click="handleClickBtn1" class="el-btn" :class="{primary:data}">外贸数据</el-button>
          <el-button @click="handleClickBtn2" class="el-btn" :class="{primary:service}">服务贸易</el-button>
          <el-button @click="handleClickBtn3" class="el-btn" :class="{primary:cross}">跨境电商</el-button>
          <el-button @click="handleClickBtn4" class="el-btn" :class="{primary:utilize}">利用外资</el-button>
          <el-button @click="handleClickBtn5" class="el-btn" :class="{primary:sales }">社零</el-button>
        </div>
        <div class="information">
          <foreign
            v-if="data&&industryList&&differentList&&townshipList"
            :list1="industryList"
            :list2="differentList"
            :list3="townshipList"
          ></foreign>
          <service v-if="service&&tradeList" :list="tradeList"></service>
          <cross v-if="cross"></cross>
          <utilize v-if="utilize&&utilizeList" :list="utilizeList"></utilize>
          <sales v-if="sales&&salesList" :list="salesList"></sales>
        </div>
      </div>
      <div class="trade" v-show="!showTab">
        <div class="content">
          <img class="trade-img" src="../../assets/imags/矢量智能对象.png" />
          <p class="trade-text">建设中</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Service from './components/Service'
import Foreign from './components/Foreign'
import Cross from './components/Cross'
import Utilize from './components/Utilize'
import Sales from './components/Sales'
import { Loading } from 'element-ui'

export default {
  name: 'Home',
  components: {
    Foreign,
    Service,
    Cross,
    Utilize,
    Sales
  },
  data () {
    return {
      showTab: true,
      tab1: 'tab',
      tab2: 'tab2',
      data: true,
      service: false,
      cross: false,
      utilize: false,
      sales: false,
      industryList: null,
      differentList: null,
      townshipList: null,
      tradeList: null,
      foreignList: null,
      salesList: null
    }
  },
  async created () {
    await this.getToken()
    const loadingInstance = Loading.service(this.$refs)
    await this.getIndustryInfo()
    await this.differentInfo()
    await this.townshipInfo()
    loadingInstance.close()
    await this.tradeInfo()
    await this.foreignInfo()
    await this.salesInfo()
  },
  methods: {
    async getToken () {
      const date = new Date()
      const y = date.getFullYear()
      let m = date.getMonth()
      const d = date.getDate()
      let hours = date.getHours()
      const fen = date.getMinutes()
      if (m < 9) {
        m = '0' + (m + 1)
      } else {
        m = m + 1
      }
      if (fen < 8) {
        hours = hours - 1
      }
      if (hours < 10) {
        hours = '0' + hours
      }
      let time = 0
      time = y + m + d + hours
      const data = {
        uss: 'hlic_01',
        info: `eZxYEc04d@REv13${time}`
      }
      const tokenRes = await this.$api.getToken(data)
      if (!tokenRes) {
        const tokenRes = await this.$api.getToken(data)
        localStorage.token = tokenRes.data.dls
        return
      }
      localStorage.token = tokenRes.data.dls
      // console.log(localStorage.token)
    },
    async getIndustryInfo () {
      const industryInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=241952366064128000',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      // console.log(industryInfo)
      this.industryList = industryInfo.data
      // console.log(this.industryList)
    },
    async differentInfo () {
      const differentInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=242224049266180096',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      // console.log(differentInfo)
      this.differentList = differentInfo.data
    },
    async townshipInfo () {
      const differentInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=241955627890462720',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      this.townshipList = differentInfo.data
    },
    async tradeInfo () {
      const tradeInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=241937326879625216',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      this.tradeList = tradeInfo.data
    },
    async foreignInfo () {
      const foreignInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=241937242070794240',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      this.utilizeList = foreignInfo.data
    },
    async salesInfo () {
      const salesInfo = await this.$api.get(
        '/task_quota/list?page=1&num=10&type=szzf&is_tz=0&task_id=241937937108914176',
        {},
        {
          headers: {
            'KBFM-0716': localStorage.token
          }
        }
      )
      this.salesList = salesInfo.data
    },
    handleTab () {
      this.showTab = true
    },
    handleTab2 () {
      // this.showTab = false
      this.$message({
        showClose: true,
        message: '建设中'
      })
    },
    handleClickBtn1 () {
      this.data = true
      this.service = false
      this.cross = false
      this.utilize = false
      this.sales = false
    },
    async handleClickBtn2 () {
      // await this.tradeInfo()
      this.data = false
      this.service = true
      this.cross = false
      this.utilize = false
      this.sales = false
    },
    handleClickBtn3 () {
      // this.data = false
      // this.service = false
      // this.cross = true
      // this.utilize = false
      // this.sales = false
      this.$message({
        showClose: true,
        message: '建设中'
      })
    },
    async handleClickBtn4 () {
      // await this.foreignInfo()
      this.data = false
      this.service = false
      this.cross = false
      this.utilize = true
      this.sales = false
    },
    async handleClickBtn5 () {
      // await this.salesInfo()
      this.data = false
      this.service = false
      this.cross = false
      this.utilize = false
      this.sales = true
    }
  }
}
</script>

<style lang="scss" scoped>
.bread {
  font-size: 16px;
  width: 100%;
  display: flex;
  color: #333333;
  align-items: center;
  padding: 10px 40px;
  box-sizing: border-box;
  justify-content: space-between;
  .l {
    display: flex;
    align-items: center;
    .normal {
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #15be50;
      width: 94px;
      height: 38px;
      color: #fff;
      border-radius: 5px;
      .i {
        font-size: 12px;
        background-color: #fff;
        border-radius: 50%;
        display: flex;
        align-items: center;
        color: #15be50;
        margin-right: 5px;
      }
    }
    .txt {
      font-weight: bold;
      margin-right: 10px;
    }
  }
  .r {
    display: flex;
    align-items: center;
    color: #000;
    img {
      width: 15px;
      height: 15px;
      margin-right: 5px;
    }
    .qian {
      margin-right: 10px;
    }
  }
}
.container {
  box-sizing: border-box;
  margin: 0 auto;
  display: flex;
  flex-direction: column;

  .title {
    height: 64px;
    margin-left: 20px;
    margin-right: 20px;
    background: linear-gradient(180deg, #1492ff 0%, #a1cff8 100%);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 14px;
    div {
      border-radius: 8px 8px 0px 0px;
      font-size: 20px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-right: 10px;
    }

    .tab {
      background: #ffffff;
      color: #337fc8;
      height: 53px;
    }
    .tab2 {
      background: #eeeeee;
      color: #666666;
      height: 43px;
    }
    .hexin {
      width: 147px;
    }
    .neiwai {
      width: 188px;
    }
  }
  .core {
    margin: 0 22px;
    .button {
      display: flex;
      justify-content: center;
      margin-bottom: 20px;
      .el-btn {
        border-radius: 8px;
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
        width: 107px;
        height: 50px;
      }
      .primary {
        background-color: #63b0f2;
        color: #ffffff;
      }
    }
  }

  .trade {
    position: absolute;
    top: 122px;
    left: 0;
    right: 0;
    bottom: 0;
    .content {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      height: 100%;
      .trade-img {
        width: 185px;
        height: 167px;
        margin-bottom: 40px;
      }
      .trade-text {
        font-size: 50px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
        text-align: center;
      }
    }
  }
}
</style>
